"""Shared stuff."""


import wx


__version__ = '0.2.1'


def is_ascii(u):
    """Determine if the `unicode` `u` only contains ASCII characters."""
    try:
        u.encode('ascii')
        return True
    except UnicodeEncodeError:
        return False

def show_ascii_error(parent):
    """Show error message about non-ASCII chars in URL, with `parent` wnd."""
    dlg = wx.MessageDialog(parent,
        u'Non-ASCII characters are not allowed in URLs. If you need them, '
        u'please escape the URL with percent encoding (%XX) as appropriate.',
        caption=u'Invalid URL', style=(wx.OK | wx.ICON_ERROR))
    dlg.ShowModal()
